#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


void solve()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    int cnt1 = 0, cnt2 = 0, ans = 0;
    for(int i = 0; i < n; i++){
        if(a[i] == 1) {
            if(i && a[i - 1] == 2) cnt1 = 0;
            cnt1++;
        }else{
            if(i && a[i - 1] == 1) cnt2 = 0;
            cnt2++;
        }
        ans = max(ans, min(cnt1, cnt2) * 2);
    }
    cout << ans << endl;
}

int main()
{
    int t = 1;
    while (t--)
        solve();
    return 0;
}